package com.example.ruiji.controller;

import com.example.ruiji.common.Result;
import com.example.ruiji.entity.AddressBook;
import com.example.ruiji.service.AddressBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/addressBook")
public class AddressBookController {

    @Autowired
    AddressBookService addressBookService;

    @PostMapping
    public Result<AddressBook> save(@RequestBody AddressBook addressBook) {
        return addressBookService.save(addressBook);
    }

    @PutMapping("default")
    public Result<AddressBook> setDefault(@RequestBody AddressBook addressBook) {
        return addressBookService.setDefault(addressBook);
    }

    @GetMapping("/id")
    public Result<AddressBook> getById(@PathVariable Long id) {
        return addressBookService.getById(id);
    }

    @GetMapping("/default")
    public Result<AddressBook> getDefault() {
        return addressBookService.getDefault();
    }

    @GetMapping("list")
    public Result<List<AddressBook>> list(AddressBook addressBook) {
        return addressBookService.list(addressBook);
    }
}
